<?php

include 'includes/utilities.php';
if(!isset($_SESSION)) {
     session_start();
}
    
$link = OpenDB();
$idPap = is_numeric($_POST["idPap"]) ? $_POST["idPap"] : -1;
$datosClinicos = mysql_real_escape_string($_POST["datos_clinicos"]);
if ($idPap == 0)
{
    $transaction = PostSQL("LOCK TABLES pap WRITE,  pap_desc_microscopica WRITE");
    $pap = GetSQLFirstValue("select IFNULL(max(id_pap),0) + 1 from pap");
    $query = "insert into pap (id_pap, numero_protocolo, datos_clinicos) values
        (" . $pap . ", " . $_SESSION["protocolo"] . ", '" . $datosClinicos . "')";
    $save = PostSQL($query);
    PostSQL("COMMIT");
    $transaction = PostSQL("UNLOCK TABLES");
} else
{
    $query = "update pap set datos_clinicos = '" . $datosClinicos . "' where id_pap = '" . $idPap . "'";
    $save = PostSQL($query);
    PostSQL("COMMIT");
}
CloseDB($link);
if ($save != false)
{
    header("Location: protPapDescMicroscopica.php");
} else
{
    ; //header("Location: error.php?error=Error al insertar");
}
?>
